package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusDeviceCropper;
import com.ruoyi.business.service.IBusDeviceCropperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农作物种植Controller
 * 
 * @author ruoyi
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/device/cropper")
@Api(tags = "设施农业-农作物")
public class BusDeviceCropperController extends BaseController
{
    @Autowired
    private IBusDeviceCropperService busDeviceCropperService;

    /**
     * 查询农作物种植列表
     */
    @GetMapping("/list")
    @ApiOperation("列表 ")
    public TableDataInfo list(BusDeviceCropper busDeviceCropper)
    {
        startPage();
        List<BusDeviceCropper> list = busDeviceCropperService.selectBusDeviceCropperList(busDeviceCropper);
        return getDataTable(list);
    }

    /**
     * 导出农作物种植列表
     */
    @PreAuthorize("@ss.hasPermi('device:cropper:export')")
    @Log(title = "农作物种植", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusDeviceCropper busDeviceCropper)
    {
        List<BusDeviceCropper> list = busDeviceCropperService.selectBusDeviceCropperList(busDeviceCropper);
        ExcelUtil<BusDeviceCropper> util = new ExcelUtil<BusDeviceCropper>(BusDeviceCropper.class);
        util.exportExcel(response, list, "农作物种植数据");
    }

    /**
     * 获取农作物种植详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:cropper:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busDeviceCropperService.selectBusDeviceCropperById(id));
    }

    /**
     * 新增农作物种植
     */
    @PreAuthorize("@ss.hasPermi('device:cropper:add')")
    @Log(title = "农作物种植", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusDeviceCropper busDeviceCropper)
    {
        return toAjax(busDeviceCropperService.insertBusDeviceCropper(busDeviceCropper));
    }

    /**
     * 修改农作物种植
     */
    @PreAuthorize("@ss.hasPermi('device:cropper:edit')")
    @Log(title = "农作物种植", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusDeviceCropper busDeviceCropper)
    {
        return toAjax(busDeviceCropperService.updateBusDeviceCropper(busDeviceCropper));
    }

    /**
     * 删除农作物种植
     */
    @PreAuthorize("@ss.hasPermi('device:cropper:remove')")
    @Log(title = "农作物种植", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busDeviceCropperService.deleteBusDeviceCropperByIds(ids));
    }
}
